/*
 * Agent.cpp
 *
 *  Created on: Jan 18, 2009
 *      Author: Andrzej Olchawa
 *      mailto: andrzejolchawa@gmail.com
 *      http://www.hardtechnology.org
 *      This is a part of the Armazd project, which is covered by
 *      GNU GPL v2 license.
 */

#include "Agent.h"

Agent::Agent()
{
	initAgent();
}

Agent::~Agent()
{
	if (listOfSensors)
	{
		list<Sensor*>::iterator it;
		for (it=listOfSensors->begin(); it!=listOfSensors->end(); it++)
		{
			delete *it;
		}
		delete listOfSensors;
	}

	if (listOfListeners)
	{
		list<Listener*>::iterator it;
		for (it=listOfListeners->begin(); it!=listOfListeners->end(); it++)
		{
			delete *it;
		}
		delete listOfListeners;
	}

	if (sensorsLoader)
	{
		delete sensorsLoader;
	}

	if (listenersLoader)
	{
		delete listenersLoader;
	}
}

void Agent::initAgent()
{
	AgentConfiguration::loadConfiguration();

	listOfSensors = new list<Sensor*>();
	listOfListeners = new list<Listener*>();
	if (listOfSensors && listOfListeners)
	{
		sensorsLoader = new SensorsLoader();
		listenersLoader = new ListenersLoader();

		createListOfSensors();
		createListOfListeners();
	}
}

list<Sensor*> *Agent::getListOfSensors()
{
	return listOfSensors;
}

list<Listener*> *Agent::getListOfListeners()
{
	return listOfListeners;
}

void Agent::createListOfSensors()
{
	if (sensorsLoader)
	{
		listOfSensors = sensorsLoader->loadSensors(listOfSensors);
	}
}

void Agent::createListOfListeners()
{
	if (listenersLoader)
	{
		listOfListeners = listenersLoader->loadListeners(listOfListeners);
	}
}
